//
//  titleView.m
//  Streaming
//
//  Created by 官琛 on 15-6-27.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "titleView.h"

@implementation titleView
- (void)dealloc
{
    [self.hotBack release];
    [self.HotView1 release];
    [self.HotImage1 release];
    [self.title1 release];
    
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        if (WIDTH == 320 && HEIGHT == 568) {
            [self creatView6];
        }
        if(WIDTH == 414 && HEIGHT == 736)
        {
            [self creatViewPlus];
            
        }
        
        if (WIDTH == 375 && HEIGHT == 667)
        {
            [self creatView6];
        }
    }
    
    return self;
}



-(void)creatView6
{
    [self afnGetRequest];
    
    
    self.hotBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.frame.size.width,230)];
    self.hotBack.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.hotBack];
    [_hotBack autorelease];
    
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction1:)];
    [self.hotBack addGestureRecognizer:tap1];
    [tap1 release];
    
    self.HotImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.hotBack.frame.size.width, self.hotBack.frame.size.height)];
    //    self.HotImage1.backgroundColor = [UIColor blueColor];
    
    [self.hotBack addSubview:self.HotImage1];
    [_HotImage1 autorelease];
    
    self.HotView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.HotImage1.frame.size.height-30, self.frame.size.width, 30)];
    self.HotView1.backgroundColor = [UIColor blackColor];
    self.HotView1.alpha = 0.7;
    self.HotView1.userInteractionEnabled = YES;
    [self.HotImage1 addSubview:self.HotView1];
    [_HotView1 autorelease];
    
    self.title1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 235, 30)];
    self.title1.numberOfLines = 0;
    self.title1.font = [UIFont boldSystemFontOfSize:20];
    self.title1.textColor = [UIColor whiteColor];
    
    //    self.title1.backgroundColor = [UIColor cyanColor];
    [self.HotView1 addSubview:self.title1];
    [_title1 autorelease];
    

    
    self.HUD = [MBProgressHUD showHUDAddedTo:self.hotBack animated:YES];
    self.HUD.labelText = @"正在加载中";
    [self.HUD show:YES];
    [self.HUD release];

}
-(void)creatViewPlus
{
    [self afnGetRequest];
    
    
    self.hotBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.frame.size.width,280)];
    self.hotBack.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.hotBack];
    [_hotBack autorelease];
    
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction1:)];
    [self.hotBack addGestureRecognizer:tap1];
    
    
    self.HotImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.hotBack.frame.size.width, self.hotBack.frame.size.height)];
    self.HotImage1.layer.shadowColor = [UIColor blackColor].CGColor;
    self.HotImage1.layer.shadowOffset = CGSizeMake(0, 3);
    self.HotImage1.layer.shadowOpacity = 0.9;
    self.HotImage1.layer.shadowRadius = 10.0;
    //    self.HotImage1.backgroundColor = [UIColor blueColor];
    
    [self.hotBack addSubview:self.HotImage1];
    [_HotImage1 autorelease];
    
    self.HotView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.HotImage1.frame.size.height-30, self.frame.size.width, 30)];
    self.HotView1.backgroundColor = [UIColor blackColor];
    self.HotView1.alpha = 0.7;
    self.HotView1.userInteractionEnabled = YES;
    [self.HotImage1 addSubview:self.HotView1];
    [_HotView1 autorelease];
    
    self.title1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 235, 30)];
    self.title1.numberOfLines = 0;
    self.title1.font = [UIFont boldSystemFontOfSize:20];
    self.title1.textColor = [UIColor whiteColor];
    
    //    self.title1.backgroundColor = [UIColor cyanColor];
    [self.HotView1 addSubview:self.title1];
    [_title1 autorelease];
    
    
    
    self.HUD = [MBProgressHUD showHUDAddedTo:self.hotBack animated:YES];
    self.HUD.labelText = @"正在加载中";
    [self.HUD show:YES];
    
}

-(void)afnGetRequest
{
    
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    NSString *url_string = @"http://api.m.mtime.cn/PageSubArea/GetFirstPageAdvAndNews.api";
    //NSString *url_string = @"http://api.m.mtime.cn/PageSubArea/HotPlayMovies.api?locationId=729";
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"application/x-javascript",@"text/html",nil];
    
    
    
    [manager GET:url_string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
        //        NSLog(@"使用AFN进行get请求 ===  %@",responseObject);
        NSMutableArray *array = [NSMutableArray array ];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        array = [responseObject objectForKey:@"hotPoints"];
        dic = [array objectAtIndex:0];
        NSURL *url1 = [NSURL URLWithString:[dic objectForKey:@"img"]];
        [self.HotImage1 sd_setImageWithURL:url1 placeholderImage:[UIImage imageNamed:@"111111.png"]];
        self.title1.text = [dic objectForKey:@"title"];
        self.newsId1 = [[dic objectForKey:@"id"]integerValue];
        
       
        
        [self.HUD hide:YES];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        [self.HUD hide:YES];
    }];
    
}


-(void)tapAction1:(UITapGestureRecognizer *)button
{

    [self.myDelegate pushHotPoint:self.newsId1];
    
}

@end
